//
//  AttentionSearchResultViewController.m
//  PropertyMananger
//
//  Created by bh on 16/12/29.
//  Copyright © 2016年 BH. All rights reserved.
//

#import "AttentionSearchResultViewController.h"
#import "AttentionCell.h"
#import "AttentionModel.h"
#import "UIView+MCCommon.h"
#import "AttentionDetailController.h"

@interface AttentionSearchResultViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) NSMutableArray *searchList;
@property (nonatomic,strong) AttentionCell *cell;
@property (nonatomic,strong) AttentionSearchResultViewController * resultVC;
@end

@implementation AttentionSearchResultViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self initTableViewWithView:self.view frame:CGRectMake(0, 0, BHscreenW, BHscreenH - 64) isGroup:NO];
}

- (void)dealloc{
    
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataSource.count;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"FollowTableViewCell";
    self.cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!self.cell) {
        self.cell = [[AttentionCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
       
        self.cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    AttentionModel * model = [self.dataSource objectAtIndex:indexPath.row];
    self.cell.nameLabel.text = model.RealName;

    self.cell.subtitle.text = model.Duty;
    
    DLog(@"===== %@---%@",model.RealName,model.Tel);
    switch (self.index) {
        case 0:
        {
        self.cell.iconImg.image = IMG(@"ico_mail_list_property");
        }
            break;
        case 1:
        {
            self.cell.iconImg.image = IMG(@"ico_owner_inquiry");
        }
            break;
        default:
            break;
    }

    return self.cell;
}
#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    DLog(@"点击了");
    
    AttentionModel * model = self.dataSource[indexPath.row];
  //  DLog(@"%@%@",model.RealName,model.Tel);
    
//    AttentionDetailController * detailVC = [[AttentionDetailController alloc]init];
//    detailVC.nickName = model.RealName;
//    detailVC.subName = model.Duty;
//    detailVC.Tel = model.Tel;
//    detailVC.OfficePhone = model.OfficePhone;
//    [self.navigationController pushViewController:detailVC animated:YES];
    if ([self.delegate respondsToSelector:@selector(resultViewController:didSelectFollowModel:)])
    {
        
        DLog(@"%@",self.dataSource[indexPath.row]);
        
        [self.delegate resultViewController:self didSelectFollowModel:self.dataSource[indexPath.row]];
        NSLog(@"搜索结果点击详情 ==== %ld",indexPath.row);
        
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 75;
}
-(void)setDataSource:(NSMutableArray *)dataSource{

    _dataSource = dataSource;
    [self.tableView reloadData];

}
@end
